package com.wuseguang.springcloud.service.impl;


import com.wuseguang.springcloud.dao.jdbc.GroupingJdbc;
import com.wuseguang.springcloud.dao.repository.GroupingRepository;
import com.wuseguang.springcloud.entity.Grouping;
import com.wuseguang.springcloud.service.GroupingService;
import com.wuseguang.springcloud.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 角色组 服务实现类
 * </p>
 *
 * @author zmc
 * @since 2019-12-06
 */
@Service
public class GroupingServiceImpl implements GroupingService {

    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private GroupingJdbc groupingJdbc;
    @Autowired
    private GroupingRepository groupingRepository;

    @Override
    public Result findGrouping(String schoolId) {

        logger.info("查询角色组");
        String sql = "select id,name  from  grouping where school_id in (0,?)";
        //查询
        List<Map<String,Object>> list = groupingJdbc.queryListMap(sql,schoolId);

        return new Result(list);
    }

    @Override
    public Result updateGrouping(Grouping grouping) {
        logger.info("修改角色组名称");
        groupingRepository.save(grouping);
        return new Result();
    }

    @Override
    public Result deleteGrouping(Integer id) {
        try {
            groupingRepository.deleteById(id);
        } catch (Exception e) {

        }
        return new Result();
    }


}
